﻿using SmartSSO.Entities;
using SmartSSO.Services;
using SmartSSO.Services.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using SmartSSO.Helpers;
using Microsoft.Practices.Unity;

namespace SmartSSO.ApiControllers
{
    public class LoginOutController : ApiController
    {
        //private readonly IUserSessionService _userSessionService = new UserSessionService();
        //private readonly IUserOperateService _userOperateService = new UserOperateService();
        private readonly IUserSessionService _userSessionService = UnityHelper.Instance.Unity.Resolve<IUserSessionService>();
        private readonly IUserOperateService _userOperateService = UnityHelper.Instance.Unity.Resolve<IUserOperateService>();

        [HttpGet]
        public string LoginOut(string sessionKey = "")
        {
            bool removeFlag = _userSessionService.Remove(sessionKey);
            if (removeFlag)
            {
                _userOperateService.Create(new UserOperateEntity
                {
                    CreateTime = DateTime.Now,
                    IpAddress = Request.RequestUri.Host,
                    Remark = "注销成功",
                    SessionKey = sessionKey
                });
            }
            return removeFlag.ToString().ToLower();
        }
    }
}
